﻿using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace DirectX_CS
{
    //SUPER IMMPORTANT ... THE COLOR MUST COME AFTER THE Z 
    //SUPER IMMPORTANT ... THE COLOR MUST COME AFTER THE Z 

public struct SVector
{
    // Summary:
    //     Retrieves the Microsoft.DirectX.Direct3D.VertexFormats for the current custom
    //     vertex.
	//SVector 
	public const VertexFormats Format = (VertexFormats)VertexFormats.Diffuse | VertexFormats.PositionNormal;//82<---position normal colored. //(VertexFormats)66 <==positioncolored

    public static int GetColorValue(System.Drawing.Color dc)
    {
		return dc.ToArgb();
    }
    public static int GetColorValue(int color)
    {
		return color;
	}
	public void SetColor(Color c)
	{
		Color = c.ToArgb();
	}
	public void SetColor(int colorARGB)
	{
		Color = colorARGB;
	}
    //
    // Summary:
    //     Retrieves or sets the x component of the position.
	[PGBrowsable]
	public float X;
    //
    // Summary:
    //     Retrieves or sets the y component of the position.
	[PGBrowsable]
	public float Y;
    //
    // Summary:
    //     Retrieves or sets the z component of the position.
	[PGBrowsable]
	public float Z;

	//// Summary:
	////     Retrieves or sets the nx component of the vertex normal.
	[PGBrowsable]
	public float Nx;
	////
	//// Summary:
	////     Retrieves or sets the ny component of the vertex normal.
	[PGBrowsable]
	public float Ny;
	////
	//// Summary:
	////     Retrieves or sets the nz component of the vertex normal.
	[PGBrowsable]
	public float Nz;    // Summary:

	//     Retrieves or sets the vertex color.
	//public int Color;// Microsoft.DirectX.Direct3D.ColorValue Color;
	[PGBrowsable]
	public int Color;

    public static int DefaultColor = System.Drawing.Color.FromArgb(0,255,0, 0).ToArgb();//System.Drawing.Color.Black.ToArgb();

    public SVector(Vector3 v, int color)
    {
        X = v.X; Y = v.Y; Z = v.Z; 
        //Rhw = default_w; 
		Nx  = 1; Ny = 1; Nz = 1;
        Color = GetColorValue(color);
        //Color = DefaultColor;
    }
    public SVector(Vector3 v, Color color)
    {
        X = v.X; Y = v.Y; Z = v.Z; 
		Nx  = 1; Ny = 1; Nz = 1;
        //Rhw = default_w; 
        //Color = color.ToArgb();
        Color = GetColorValue(color);
        //Color = DefaultColor;
    }
    public SVector(Vector3 v)
    {
        X = v.X; Y = v.Y; Z = v.Z; 
		Nx  = 1; Ny = 1; Nz = 1;
        //Rhw = default_w; 
        Color = GetColorValue(DefaultColor);
        //Color = DefaultColor;
    }
   
    public SVector(Vector4 transformedPosition, Color c)
    {
        X = transformedPosition.X; Y = transformedPosition.Y; Z = transformedPosition.Z; 
		Nx  = 1; Ny = 1; Nz = 1;
        //Rhw = transformedPosition.W;
        Color = GetColorValue(c);
        //Color = DefaultColor;
    }   
    public SVector(Vector4 transformedPosition, int color)
    {
        X = transformedPosition.X; Y = transformedPosition.Y; Z = transformedPosition.Z;
		Nx  = 1; Ny = 1; Nz = 1;
        //Rhw = transformedPosition.W;
        Color = GetColorValue(color);
        //Color = DefaultColor;
    }
    
    public static SVector operator+(SVector lVec, SVector rVec)
    {
        SVector sum = new SVector(lVec.X + rVec.X, lVec.Y+rVec.Y, lVec.Z + rVec.Z);
        return sum;
    }
    /*
    public static SVector operator+=(SVector rVec)
    {
        X = X + rVec.X;
        Y = Y + rVec.Y;
        Z = Z + rVec.Z;
        return this;
    }              */
    public SVector(float x, float y, float z)
    {
        X = x; Y = y; Z = z;
		Nx  = 1; Ny = 1; Nz = 1;
        //Rhw = default_w; 
        Color = GetColorValue(DefaultColor);
        //Color = DefaultColor;
    }
    public SVector(float x, float y, float z, Color color)
    {
        X = x; Y = y; Z = z; 
		Nx  = 1; Ny = 1; Nz = 1;
        //Rhw = default_w; 
        Color = GetColorValue(color);
        //Color = DefaultColor;
    }
    public SVector(float x, float y, float z, float nx, float ny, float nz, Color color)
    {
        X = x; Y = y; Z = z; 
		Nx  = nx; Ny = ny; Nz = nz;
        //Rhw = default_w; 
        Color = GetColorValue(color);
        //Color = DefaultColor;
    }
	public SVector(float x, float y, float z, float nx, float ny, float nz, int color)
	{
		X = x; Y = y; Z = z;
		Nx = nx; Ny = ny; Nz = nz;
		//Rhw = default_w; 
		Color = GetColorValue(color);
		//Color = DefaultColor;
	}
	public SVector(Vector3 position, Vector3 normal)
	{
		X = position.X; Y = position.Y; Z = position.Z;
		Nx = normal.X; Ny = normal.Y; Nz = normal.Z;
		//Rhw = default_w; 
		Color = GetColorValue(DefaultColor);
		//Color = DefaultColor;
	}
	public SVector(Vector3 position, Vector3 normal, Color color)
	{
		X = position.X; Y = position.Y; Z = position.Z;
		Nx = normal.X; Ny = normal.Y; Nz = normal.Z;
		//Rhw = default_w; 
		Color = GetColorValue(color);
		//Color = DefaultColor;
	}
	public SVector(Vector3 position, Vector3 normal, int color)
	{
		X = position.X; Y = position.Y; Z = position.Z;
		Nx = normal.X; Ny = normal.Y; Nz = normal.Z;
		//Rhw = default_w; 
		Color = GetColorValue(color);
		//Color = DefaultColor;
	}
    public SVector(float x, float y, float z, float nx, float ny, float nz)
    {
        X = x; Y = y; Z = z; 
		Nx  = nx; Ny = ny; Nz = nz;
        //Rhw = default_w; 
        Color = GetColorValue(DefaultColor);
        //Color = DefaultColor;
    }
    public SVector(float x, float y, float z, int color)
    {
        X = x; Y = y; Z = z;
		Nx  = 1; Ny = 1; Nz = 1;
        //Rhw = default_w; 
        Color = GetColorValue(color);
        //Color = DefaultColor;
    }
	
    public Vector3 Position
    {
        get { return new Vector3(X, Y, Z);} 
        set { 
            X = value.X; 
            Y = value.Y; 
            Z = value.Z; 
            //Rhw = value.W; 
        }
    }
	public Vector3 Normal
	{
		get { return new Vector3(Nx, Ny, Nz); }
		set { Nx = value.X; Ny = value.Y; Nz = value.Z; }
	}
	//public static int StrideSize 
	//{
	//    get
	//    {
	//        //SVector pc = new SVector(0, 0, 0, 0);
	//        return SVector.StrideSize;
	//    }
	//}

	
	public static VertexElement[] VertexElements
	{
		get 
		{
			//VertexElement[] elems = new VertexElement[] 
			//{
			//    new VertexElement(0, 0, DeclarationType.Float3,DeclarationMethod.Default, DeclarationUsage.Position, 0),
			//    new VertexElement(0, sizeof(float)*3, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
			//};
			//return elems;
			return VertexInformation.DeclaratorFromFormat(Format);
		}
	}

	public static int SizeInBytes = sizeof(float) * (6 + 1); // sizeof(float) * (3 + 1); for positioncolored

    public override string ToString()
    {
        return (X.ToString() + " " + Y.ToString() + " " + Z.ToString() + " ");    
    }

} //END OF CLASS
} //END OF NAMESPACE
